#include "qlogger.hpp"

void QLoggerAppender::streamWrite (QTextStream &stream, const QLoggerEvent &event)
{
    QString message = QString(_format);
    message.replace("%d", event.dateTime.toString("dd.MM.yyyy hh:mm:ss.zzz"));
    message.replace("%r", QString("%1").arg(QLoggerEngine::handle().elapsed()));
    message.replace("%l", QLoggerEngine::levelName(event.level));
    message.replace("%c", event.logger->name);
    message.replace("%i", QString("%1").arg(event.line));
    message.replace("%f", QString(event.file));
    message.replace("%m", *(event.message));
    message.replace("%n", "\n");
    stream << message;
    stream.flush();
}

QLoggerAppender::QLoggerAppender (const QString &format, int level)
{
    _level = (QLoggerEngine::QLoggerLevel) level;
    if (format.isNull())
        _format = "%d - <%l> - {%c} -- %m%n";
    else
        _format = format;
}

QLoggerEngine::QLoggerLevel QLoggerAppender::level ()
{
    return _level;
}
